package net.lab1024.sa.admin.module.business.erp.bas.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.erp.bas.dao.SiteordDao;
import net.lab1024.sa.admin.module.business.erp.bas.domain.entity.SiteordEntity;
import net.lab1024.sa.admin.module.business.erp.bas.domain.form.SiteordAddForm;
import net.lab1024.sa.admin.module.business.erp.bas.domain.form.SiteordQueryForm;
import net.lab1024.sa.admin.module.business.erp.bas.domain.form.SiteordUpdateForm;
import net.lab1024.sa.admin.module.business.erp.bas.domain.vo.SiteordVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 发货通知单 Service
 *
 * @Author sp
 * @Date 2025-11-12 17:06:24
 * @Copyright sp
 */

@Service
public class SiteordService {

    @Resource
    private SiteordDao siteordDao;

    /**
     * 分页查询
     */
    public PageResult<SiteordVO> queryPage(SiteordQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<SiteordVO> list = siteordDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(SiteordAddForm addForm) {
        SiteordEntity siteordEntity = SmartBeanUtil.copy(addForm, SiteordEntity.class);
        siteordDao.insert(siteordEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(SiteordUpdateForm updateForm) {
        SiteordEntity siteordEntity = SmartBeanUtil.copy(updateForm, SiteordEntity.class);
        siteordDao.updateById(siteordEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        siteordDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        siteordDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
